// pages/myStatus/myStatus.js
const ajax = require("../../utils/ajax")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    heightPeople:'',
    weight:'',
    bloodPressure:'',
    bloodSugar:'',
    limbs:'',
    active:'',
    listen:'',
    articulation:'',
    heart:'',
    phone:''
  },
  gtePeopleInfo(){
    const requestParam = {
      userId: wx.getStorageSync('UserNo')
    }
    ajax.requestPost({
      url:'applet/user/getPeopleInfo',
      data: requestParam,
      success: res => {
        console.log(res)
        this.setData({
          heightPeople: res.data.data.heightPeople,
          weight:res.data.data.weight,
          bloodPressure:res.data.data.bloodPressure,
          bloodSugar:res.data.data.bloodSugar,
          limbs:res.data.data.limbs,
          active:res.data.data.active,
          listen:res.data.data.listen,
          articulation:res.data.data.articulation,
          heart:res.data.data.heart,
          phone: res.data.data.phone,
        })
      }
    })
  },
  save(){
    const requestParam = {
      heightPeople: this.data.heightPeoploe,
      weight:this.data.weight,
      bloodPressure:this.data.bloodPressure,
      bloodSugar:this.data.bloodSugar,
      limbs:this.data.limbs,
      active:this.data.active,
      listen:this.data.listen,
      articulation:this.data.articulation,
      heart:this.data.heart,
      phone: this.data.phone,
      userId: wx.getStorageSync('UserNo')
    }
    if(this.data.phone == null || this.data.phone == ''){
      return wx.showToast({
        title: '手机号必须填',
        icon: 'none',
        duration: 2000,
      });
    }
    ajax.requestPost({
      url:'applet/user/updateBody',
      data: requestParam,
      success: res => {
        wx.showToast({
          title: '操作成功',
          icon: 'success',
          duration: 2000,
        });
        setTimeout(()=>{
        wx.navigateBack({
          dalta: 1
        })
        }, 1500)
      }
    })
  },
  input10(e){
    this.setData({
      phone : e.detail.value
    })
  },
  input9(e){
    this.setData({
      heart : e.detail.value
    })
  },
  input8(e){
    this.setData({
      articulation : e.detail.value
    })
  },
  input7(e){
    this.setData({
      listen : e.detail.value
    })
  },
  input6(e){
    this.setData({
      active : e.detail.value
    })
  },
  input5(e){
    this.setData({
      limbs : e.detail.value
    })
  },
  input4(e){
    this.setData({
      bloodSugar : e.detail.value
    })
  },
  input3(e){
    this.setData({
      bloodPressure : e.detail.value
    })
  },
  input1(e){
    console.log(e.detail.value)
    this.setData({
      heightPeoploe : e.detail.value
    })
  },
  input2(e){
    this.setData({
      weight : e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.gtePeopleInfo()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})